import 'package:http/http.dart' as http;
import 'dart:convert';

//输出响应正文
printResponseBody(response) {
  //输出响应正文的长度
  print(response.body.length);
  //控制输出的长度在100以内
  if (response.body.length > 1000) {
    print(response.body.substring(0, 1000));
  } else {
    print(response.body);
  }
  print('...\n');
}

main(List<String> arguments) {
  var url = 'http://39.108.246.130/api';
  //Client类，保持持久连接，向同一个服务器发多个请求
  var client = new http.Client();
  //第一次请求
  client.post('$url/auth/login', body: "{\"account\":\"admin\",\"password\":\"admin123456\"}").then((response) {
    printResponseBody(response);

    var jsonObject = json.decode(response.body);
    print(jsonObject.toString());

    //第二次请求
    return client.post('$url/auth/login', body: "{\"account\":\"admin\",\"password\":\"admin\"}");
  })
  .then(printResponseBody)
  //完成后关闭Client连接
  .whenComplete(client.close);
}